package com.lambda;

import com.bean.Dog;

import java.lang.reflect.Constructor;

public class SimpleConstrunctor {

    public static void main(String[] args) {
        Dog r = new Dog();
       // printConstructors(r);
        printInterfaceNames(r);
    }

    public static void printConstructors(Dog r) {
        Class c = r.getClass();
        //获取指定类的类名
        String className = c.getName();
        try {
            //获取指定类的构造方法
            Constructor[] theConstructors = c.getConstructors();
            for (int i = 0; i < theConstructors.length; i++) {
                //获取指定构造方法的参数的集合
                Class[] parameterTypes = theConstructors[i].getParameterTypes();

                System.out.print(className + "(");

                for (int j = 0; j < parameterTypes.length; j++)
                    System.out.print(parameterTypes[j].getName() + " ");

                System.out.println(")");

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void printInterfaceNames(Object o) {
        Class c = o.getClass();
        //获取反射类的接口
        Class[] theInterfaces = c.getInterfaces();
        for (int i = 0; i < theInterfaces.length; i++)
            System.out.println(theInterfaces[i].getName());
        //获取反射类的父类（超类）
        Class theSuperclass = c.getSuperclass();
        System.out.println(theSuperclass.getName());
    }
}
